<?php

namespace App\Http\Controllers\Frontend;

use App\Ad;
use App\Post;
use Illuminate\Http\Request;

class HomeController extends BaseController
{
    public function index()
    {
        $ads = Ad::where('position', 1)->orderBy('order')->limit(5)->get();
        $notice = Post::where('category_id', 17)->limit(1)->latest()->select('id', 'title')->first();
        $hot = Post::latest()->where('category_id', '<>', 15)->where('category_id', '<>', 17)->select('id', 'title', 'description')->first();
        $postGroup1 = Post::where('category_id', 8)->limit(5)->latest()->select('id', 'title', 'created_at')->get();
        $postGroup2 = Post::where('category_id', 15)->limit(3)->latest()->select('id', 'title', 'created_at')->get();
        $postGroup3 = Post::where('category_id', 17)->limit(4)->latest()->select('id', 'title', 'created_at')->get();
        $postGroup4 = Post::where('category_id', 7)->limit(4)->latest()->select('id', 'title', 'created_at')->get();
        $postGroup5 = Post::where('category_id', 10)->limit(4)->latest()->select('id', 'title', 'created_at')->get();
        $postGroup6 = Post::where('category_id', 11)->limit(4)->latest()->select('id', 'title', 'created_at')->get();
        return view('frontend.home.index', compact(['ads', 'notice', 'hot',  'postGroup1', 'postGroup2', 'postGroup3', 'postGroup4', 'postGroup5', 'postGroup6']));

    }

    protected function _getPosts($category, $limit=5)
    {
        return Post::where('category_id', $category)->limit($limit)->get();
    }

}
